package com.wjk.kylin.id.core.util;


import com.wjk.kylin.id.core.factory.impl.IdGeneratorFactoryClient;
import com.wjk.kylin.id.core.generator.IdGenerator;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;


/**
 * @author wangjinkui
 * @since 1.0.0
 */

public class IdUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(IdUtil.class);
    private static final IdGeneratorFactoryClient CLIENT = IdGeneratorFactoryClient.getInstance();

    private IdUtil() {
    }
    // ------------------------------------------------------------------- UUID


    // ------------------------------------------------------------------- 自增

    /**
     *
     * @param bizType
     * @return
     */
    public static Long nextId(String bizType) {
        if (StringUtils.isBlank(bizType)) {
            throw new IllegalArgumentException("bizType is null");
        }
        IdGenerator generator = CLIENT.getIdGenerator(bizType);
        return generator.nextId();
    }

    /**
     *
     * @param bizType
     * @param batchSize
     * @return
     */
    public static List<Long> nextId(String bizType, Integer batchSize) {
        if (batchSize == null || batchSize <= 1) {
            Long id = nextId(bizType);
            List<Long> list = new ArrayList<>();
            list.add(id);
            return list;
        } else {
            IdGenerator idGenerator = CLIENT.getIdGenerator(bizType);
            return idGenerator.nextId(batchSize);
        }
    }
}
